package com.wgh.product.service.impl;

import com.wgh.product.entity.shop.Brand;
import com.wgh.product.mapper.BrandMapper;
import com.wgh.product.service.BrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 品牌Service实现类
 * 
 * @author AI Shop
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    @Override
    public List<Brand> getEnabledBrands() {
        return baseMapper.selectEnabledBrands();
    }

    @Override
    public Brand getBrandByName(String name) {
        return baseMapper.selectByName(name);
    }

    @Override
    public List<Brand> getBrandsByFirstLetter(String firstLetter) {
        return baseMapper.selectByFirstLetter(firstLetter);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateStatusBatch(List<Long> ids, Integer status) {
        return baseMapper.updateStatusBatch(ids, status) > 0;
    }

    @Override
    public int countProductsByBrandId(Long brandId) {
        return baseMapper.countProductsByBrandId(brandId);
    }

    @Override
    public List<Brand> searchBrands(String keyword) {
        return baseMapper.searchBrands(keyword);
    }

    @Override
    public List<Brand> getBrandPage(Integer pageNum, Integer pageSize) {
        Page<Brand> page = new Page<>(pageNum, pageSize);
        Page<Brand> brandPage = baseMapper.selectPage(page, null);
        return brandPage.getRecords();
    }
}